package com.menggudf.service.impl;

import com.menggudf.entity.Illness;
import com.menggudf.mapper.IllnessDao;
import com.menggudf.service.IllnessService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (Illness)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:28
 */
@Service("illnessService")
public class IllnessServiceImpl implements IllnessService {
    @Resource
    private IllnessDao illnessDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Illness queryById(Integer id) {
        return this.illnessDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param illness 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Illness> queryByPage(Illness illness, PageRequest pageRequest) {
        long total = this.illnessDao.count(illness);
        return new PageImpl<>(this.illnessDao.queryAllByLimit(illness, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param illness 实例对象
     * @return 实例对象
     */
    @Override
    public Illness insert(Illness illness) {
        this.illnessDao.insert(illness);
        return illness;
    }

    /**
     * 修改数据
     *
     * @param illness 实例对象
     * @return 实例对象
     */
    @Override
    public Illness update(Illness illness) {
        this.illnessDao.update(illness);
        return this.queryById(illness.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.illnessDao.deleteById(id) > 0;
    }
}
